#ifndef NIXONBOT_CORE_BNCS_PROTOCOL_ACCOUNTLOGONSERVER_H_
#define NIXONBOT_CORE_BNCS_PROTOCOL_ACCOUNTLOGONSERVER_H_

#include <nixonbot/core/bncs/protocol/Message.h>
#include <nixonbot/core/bncs/protocol/MessageFactory.h>

namespace nixonbot {
namespace core {
namespace bncs {
namespace protocol {

struct AccountLogonServerData : public QSharedData
{
  quint32 status;
  quint8 salt[32];
  quint8 serverKey[32];
};

class AccountLogonServer : public Message
{
public:
	static const int id = 0x53;
	BNCS_MESSAGE_SERVER_REGISTER(AccountLogonServer, id);

public:
	QSharedDataPointer<AccountLogonServerData> d;

public:
	AccountLogonServer()
	{
		d = new AccountLogonServerData();
	}
	
	virtual AccountLogonServer* create()
	{
		return new AccountLogonServer();
	}
	
	virtual quint32 id()
	{
		return id;
	}

	virtual int size()
	{
	  return sizeof(d->status) + sizeof(d->salt) + sizeof(d->serverKey);
	}

protected:
	void readFrom(QDataStream& ds)
	{
		int bo = ds.byteOrder();
		ds.setByteOrder(QDataStream::LittleEndian);

		ds >> status;
		ds.readRawData((char*)salt, 32);
		ds.readRawData((char*)serverKey, 32);

		ds.setByteOrder((QDataStream::ByteOrder)bo);
	}

	void writeTo(QDataStream& ds)
	{
		int bo = ds.byteOrder();
		ds.setByteOrder(QDataStream::LittleEndian);

		ds << status;
		ds.writeRawData((char*)salt, 32);
		ds.writeRawData((char*)serverKey, 32);

		ds.setByteOrder((QDataStream::ByteOrder)bo);
	}
};

}
}
}
}

#endif /*NIXONBOT_CORE_BNCS_PROTOCOL_ACCOUNTLOGONSERVER_H_*/
